"""
Copyright 2009, Thomas Dejanovic, Jay Shurtz.
 
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.
"""

id = "$Id: hatch_txt.py 667 2010-07-01 00:12:17Z jayshurtz $"
# $URL: http://hatch.googlecode.com/svn/tags/taggle_release_3.0/hatch/hatch_targets/hatch_txt.py $
# $Author: jayshurtz $
version = " ".join(id.split()[1:3])


from os import extsep
import to_hatch_structure
from hatch_log import *


def generate(hatchNode, moduleName):
    """ 'hatchNode' is the top node of the design.
        'moduleName' is the basename of the design file.
    """
    logger.info(generate.func_name + "(" + hatchNodeClassAndName(hatchNode) + ", " + str(moduleName) + ")")
    outputFile = open(moduleName + extsep + "txt", 'w')
    outputFile.write(hatchNode.info())  # Write to file.  
    outputFile.close()


# TODO - built-in-self-test 
if __name__ == "__main__":
    #import hatch_history
    #hatch_history.setupSimpleHistory(histfile=__file__.replace('.py','.pyhist'), length=500)  # Setup history for this file.
    #consoleHandler.setLevel(logging.DEBUG)

    if True:
        from hatch_nodes.hatch_node_physical import HatchNodePhysical
        h0 = HatchNodePhysical('h0', hw='rwdicsp')
        h1 = HatchNodePhysical('h1', sw='rwt', sw_load_enable=2, auto_clear_on=0x233)
        h2 = HatchNodePhysical('h2', auto='dicspt', auto_clear_on=0x123, auto_set_on='bloo', auto_trigger_on='23', trigger_count=6)
        h3 = HatchNodePhysical('h3', comment="blabla!", input_ports='ip', output_ports='op')
        h4 = HatchNodePhysical('h4', rtl="RTL IS HERE")
        h5 = HatchNodePhysical('h5', auto_error_detect=1, auto_error_correct=1)
        h6 = HatchNodePhysical('h6', auto_error_detect=4, auto_error_correct=4)

        hatchling = hatchBlock
        generate(hatchling, "hatch_txt_test")
        print "Please check the 'hatch_txt_test.txt' file."


